#!/usr/bin/env node

const http = require('https'),
      log = console.log,
      addr = 'https://ke.sifou.com/free',
      baseurl = 'https://ke.sifou.com/',
      cheerio = require('cheerio');

http.get(addr,(res)=>{
  let data = '';
  res.on('data',(chunk)=>{data += chunk;});
  res.on('end',()=>{
    //log(data)
    let $ = cheerio.load(data);
    let courses = $('body').find('h5.card-title>a');
    for(let i = 0;i<courses.length;i++){
      //打出来的是dom结构
      log($(courses[i]).text());
      log(baseurl+$(courses[i]).attr('href'));
      log('');
    }

  });

  //or 
  //res.pipe(process.stdout);
})
